package com.zs.toolbox.web2j.system.message.service.impl;

import com.zs.toolbox.web2j.system.message.sender.sms.WtSmsSender;
import com.zs.toolbox.web2j.system.message.service.WtSmsService;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author shuai.zhang  on 2018/9/25
 * @description
 */
@Slf4j
public class WtSmsServiceImpl implements WtSmsService {
    List<WtSmsSender> senders;

    public List<WtSmsSender> getSenders() {
        return senders;
    }

    public WtSmsServiceImpl setSenders(List<WtSmsSender> senders) {
        this.senders = senders;
        return this;
    }

    @Override
    public Boolean sendRegisterVCodeSms(String phone, String vcode) {
        for (WtSmsSender sender : senders) {
            if (sender.sendRegisterVCodeSms(phone, vcode)) {
                log.debug("send register sms from sender<{}> to phone<{}> code<{}> success", sender.getName(), phone, vcode);
                return true;
            }
        }
        log.warn("send register sms from to phone<{}> code<{}> failed", phone, vcode);
        return false;
    }

    @Override
    public Boolean sendLoginVCodeSms(String phone, String vcode) {
        for (WtSmsSender sender : senders) {
            if (sender.sendLoginVCodeSms(phone, vcode)) {
                log.debug("send login sms from sender<{}> to phone<{}> code<{}> success", sender.getName(), phone, vcode);
                return true;
            }
        }
        log.warn("send login sms from to phone<{}> code<{}> failed", phone, vcode);
        return false;
    }


    @Override
    public Boolean sendFindPasswordSms(String phone, String vcode) {
        for (WtSmsSender sender : senders) {
            if (sender.sendFindPasswordVCodeSms(phone, vcode)) {
                log.debug("send find password sms from sender<{}> to phone<{}> code<{}> success", sender.getName(), phone, vcode);
                return true;
            }
        }
        log.warn("send find password sms from to phone<{}> code<{}> failed", phone, vcode);
        return false;
    }

}
